<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>正则表达式</title>
</head>
<body>
<script>
    var name = "aaaaa";
    var reg = new RegExp("^[a-zA-Z][\\d\\w\\.\\_]{4,19}$", "g");
    var result;
    while ((result = reg.exec(name)) != null) {
        document.write(result);
        document.write("<br />");
        document.write(reg.lastIndex);
    }

    var result2 = reg.test(name);
    document.write("<br />");
    document.write(result2);
    document.write("<br />");

    var str = "Every man in the world! Every woman on earth!";
    var patt = /man/g;
    var str2 = str.replace(patt, "person");
    document.write(str2 + "<br />");
    var patt = /(wo)?man/g;
    patt.compile(patt);
    var str2 = str.replace(patt, "person");
    document.write(str2);

    document.write("<br />");
    var str="Visit W3School!"
    document.write(str.search(/w3School/i));

    document.write("<br />");
    var str="Hello world!"
    document.write(str.match("world") + "<br />")
    document.write(str.match(/World/i) + "<br />")
    document.write(str.match("worlld") + "<br />")
    document.write(str.match("world!"))

</script>
</body>
</html>